#include <stdio.h>
#include <stdlib.h>
#include <math.h>
// #ifdef _OPENMP
#include <omp.h>
// #endif /* _OPENMP */
#include <sys/timeb.h>


// # define N 10000000

int main(int argc, char *argv[])
{
 int nCPU, tid, nthreads, /*j,*/ flag_dynamic, flag_nested;
/*
 double sum;
 struct timeb t1, t2;

 ftime(&t1);*/


#pragma omp parallel private(nCPU, nthreads, flag_dynamic, flag_nested, tid)
  {
 /* get the total number of processors available for OpenMP */
    nCPU = omp_get_num_procs();

 /* get the total number of threads available in this parallel region */
    nthreads = omp_get_num_threads();

 /* Dynamic threading. */
    omp_set_dynamic(1); /* Enable. */
    flag_dynamic = omp_get_dynamic(); /* Testing */

 /* Nested threading. */
    omp_set_nested(1); /* Enable. */
    flag_nested = omp_get_nested(); /* Testing */

 /* get the current thread ID in the parallel region */
    tid = omp_get_thread_num();

 /* only execute this on the master thread! */
    if(tid == 0)
       {
        printf("%i : Number of processors = %i\n",tid, nCPU);
        printf("%i : Number of threads in this parallel section = %i\n",tid, nthreads);

        if(flag_dynamic == 1) printf("%i : Dynamic threads are SUPPORTED.\n", tid);
        else printf("%i : Dynamic threads are NOT supported.\n", tid);

        if(flag_nested == 1) printf("%i : Nested threads are SUPPORTED.\n", tid);
        else printf("%i : Nested threads are NOT supported.\n", tid);
       }

    printf("%i : Hello from thread no. %i out of total %i threads.\n", tid, tid, nCPU);
/*
    #pragma omp for private(j) reduction(+: sum)
     for(j = 1; j <= N; j++) sum += j/log(log(N));*/
  }
//  ftime(&t2);

//  printf("Sum = %E, dt = %ld ms\n", sum, (t2.time-t1.time)*1000+t2.millitm-t1.millitm);

 return 0;
}
